package com.earnings.okhttputils.utils.ui.activity.user;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.earnings.R;
import com.earnings.okhttputils.utils.OkHttp.OkHttpUtils;
import com.earnings.okhttputils.utils.OkHttp.utils.ToastUtils;
import com.earnings.okhttputils.utils.UrlConstant.HttpUrl;
import com.earnings.okhttputils.utils.adapter.DataBindingBaseadapter;
import com.earnings.okhttputils.utils.bean.RecommendFriendsData;
import com.earnings.okhttputils.utils.bean.RecommendFriendsListData;
import com.earnings.okhttputils.utils.god.GodAdapter.GodBaseAdapter;
import com.earnings.okhttputils.utils.god.GodAdapter.GodViewHolder;
import com.earnings.okhttputils.utils.god.GodLeftHandBaseActivity;
import com.earnings.okhttputils.utils.https.HttpMap;
import com.earnings.okhttputils.utils.https.HttpObjectCallback;

import java.util.ArrayList;
import java.util.Map;


/*
推荐的好友
 */
public class UserRecommendedFriendsActivity extends GodLeftHandBaseActivity {

    private RecyclerView rvMsg;
    private DataBindingBaseadapter baseadapter;
    private ArrayList<RecommendFriendsListData> datas;

    @Override
    protected int onCreateLayoutId() {
        return R.layout.activity_user_recommened;
    }

    @Override
    protected void init() {
        setTitle( "推荐的好友" );
        rvMsg = (RecyclerView) findViewById( R.id.recyclerview );

        loadData();
    }


    public void initData() {

        setRecyclerViewLayoutManager( R.id.recyclerview, new LinearLayoutManager( this ) ).setAdapter( new GodBaseAdapter<RecommendFriendsListData>( R.layout.item_recommened ,datas) {
            @Override
            public void onBind(GodViewHolder holder, int position, RecommendFriendsListData data) {
                holder.setText( R.id.name, datas.get( position ).getNickname() );
                holder.setText( R.id.info, datas.get( position ).getType() );
                holder.setText( R.id.count, datas.get( position ).getRichchange() );
                holder.setText( R.id.date, datas.get( position ).getCreatetime() );

            }
        } );

    }

    public void loadData() {

        Map map = new HttpMap( getContext() );

        OkHttpUtils.post().url( HttpUrl.USER_RECOMMEND_FRIENDS_URL ).params( map ).build().execute( new HttpObjectCallback<RecommendFriendsData>( getContext() ) {
            @Override
            public void onSuccess(RecommendFriendsData object, String msg) {
                datas = (ArrayList<RecommendFriendsListData>) object.getList();
                initData();
            }

            @Override
            public void onFail(int code, String msg) {

                ToastUtils.showToast( getContext(), msg );
            }


        } );


    }


    public void loadDataForPhone() {

        Map map = new HttpMap( getContext() );

        OkHttpUtils.post().url( HttpUrl.USER_RECOMMEND_FRIENDS_URL ).params( map ).build().execute( new HttpObjectCallback<RecommendFriendsData>( getContext() ) {
            @Override
            public void onSuccess(RecommendFriendsData object, String msg) {
                datas = (ArrayList<RecommendFriendsListData>) object.getList();
                initData();
            }

            @Override
            public void onFail(int code, String msg) {

                ToastUtils.showToast( getContext(), msg );
            }


        } );


    }
}
